﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

public partial class MainMaster : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        NavDataBind();
        lab_User.Text = CMSUser.Current.Name+",你好，欢迎使用本系统！";
    }

    //显示类型
    private void NavDataBind()
    {
        this.ASPxNavType.Groups.Clear();
        this.ASPxNavType.Font.Size = FontUnit.Parse("10pt");
        if (Cache["NavDatalist"] == null)        //获取或设置指定键外的缓存项
        {
            using (DataClassesDataContext dc = new DataClassesDataContext())
            {
                Cache["NavDatalist"] = dc.css_action.ToList();
            }
        }

        //先获取数据
        List<css_action> AllList = Cache["NavDatalist"] as List<css_action>;          //所有内容
        List<css_action> groupList = AllList.Where(o => o.mid == "0").ToList();     //一级节点
        foreach (css_action group in groupList)
        {
            DevExpress.Web.ASPxNavBar.NavBarGroup NvGroup = this.ASPxNavType.Groups.Add(group.ades, group.aid);   //显示内容
            List<css_action> itemlist = AllList.Where(o => o.mid == group.aid).ToList();   //列出对应的二级内容
            foreach (css_action item in itemlist)
            {
                //判断是否拥有操作权限
                if (CMSUser.Current.CheckActionAllow(item.aid))
                {
                    NvGroup.Items.Add(item.ades, item.aid, string.Empty, item.afun);
                }
            }
        }
    }

    protected void linkbtn_Exit_Click(object sender, EventArgs e)
    {
        HttpContext.Current.Session.Clear();
        Response.Redirect("~/login.aspx");
    }
}
